<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;


/**
 * App\Models\Menu
 *
 * @property int $id
 * @property int $menuid
 * @property int $fid
 * @property string|null $name
 * @property string|null $url
 * @property string $type
 * @property string|null $icon
 * @property string $target
 * @property int $displayorder
 * @property int $available
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Menu[] $items
 * @property-read \App\Models\Menu $menu
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu available()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu onlyMenu()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereAvailable($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereDisplayorder($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereFid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereIcon($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereMenuid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereTarget($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereUrl($value)
 * @mixin \Eloquent
 */
class Menu extends Model
{
    protected $table = 'menu';
    protected $primaryKey = 'id';
    protected $fillable = ['menuid', 'fid', 'name', 'url', 'type', 'icon', 'target', 'displayorder', 'available'];

    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function items()
    {
        return $this->hasMany(Menu::class, 'menuid', 'id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function menu()
    {
        return $this->belongsTo(Menu::class, 'menuid', 'id');
    }

    /**
     * @param Builder $builder
     * @return Builder
     */
    public function scopeOnlyMenu(Builder $builder)
    {
        return $builder->where('type', 'menu');
    }

    /**
     * @param Builder $builder
     * @return Builder
     */
    public function scopeAvailable(Builder $builder)
    {
        return $builder->where('available', 1);
    }
}
